#include <stdio.h>
#include <stdlib.h>

#include "hpcr_types.h"
#include "core/hpcr_list.h"
#include "core/hpcr_memory.h"

struct data
{
    hpcr_list_node_t item;
    char name[16];
    int age;
};

typedef struct data data_t;

int main()
{
    void *buffer = malloc(512);
    hpcr_memory_pool_t mp;
    hpcr_memory_pool_t *mpp = &mp;
    hpcr_memory_pool_init(mpp, buffer, 512);
    data_t *dat_p1 = (data_t *)hpcr_memory_alloc(mpp, sizeof(data_t));
    data_t *dat_p2 = (data_t *)hpcr_memory_alloc(mpp, sizeof(data_t));

    printf("%lu %lu %lu %lld\n", sizeof(hpcr_list_node_t), sizeof(hpcr_memory_header_t), sizeof(data_t), (hpcr_uint64_t)dat_p1 - (hpcr_uint64_t)dat_p2);

    printf("%llu\n", (hpcr_uint64_t)dat_p1);
    printf("%llu\n", (hpcr_uint64_t)dat_p2);
    hpcr_memory_free(mpp, dat_p1);
    hpcr_memory_free(mpp, dat_p2);
    dat_p1 = (data_t *)hpcr_memory_alloc(mpp, sizeof(data_t));
    dat_p2 = (data_t *)hpcr_memory_alloc(mpp, sizeof(data_t));
    printf("%llu\n", (hpcr_uint64_t)dat_p1);
    printf("%llu\n", (hpcr_uint64_t)dat_p2);

    for (int i = 0; i < 7; i++)
    {
        dat_p1 = (data_t *)hpcr_memory_alloc(mpp, sizeof(data_t));
        printf("%llu\n", (hpcr_uint64_t)dat_p1);
    }

    return 0;
}